package com.zuoqi.easywork.moneyManage.controller;

import com.github.pagehelper.Page;
import com.zuoqi.common.utils.IMap;
import com.zuoqi.common.utils.PageView;
import com.zuoqi.common.utils.ReturnMapUtils;
import com.zuoqi.common.utils.SessionUtil;
import com.zuoqi.easywork.moneyManage.service.FundService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;
import java.util.Map;

@Controller
public class fundManageCon {
    @Autowired
    private FundService fundService;

    @RequestMapping(value = "/fundManageCon/toPage/fundManageView")
    public String fundManageView(ModelMap modelMap){
        IMap fundInfo = fundService.getFundInfo();
        modelMap.addAttribute("fundInfo",fundInfo);
        return "/module/moneyManage/fundManage";
    }
    @RequestMapping(value = "/fundManageCon/ajax/addFund",method = RequestMethod.POST)
    @ResponseBody
    public Map addFund(HttpServletRequest request){
        IMap params = new IMap(request);
        HttpSession session = request.getSession();
        String userId = SessionUtil.getLoginUserId(session);
        params.put("updateUser",userId);
        int i = fundService.addFund(params);
        if (i==1){
            return ReturnMapUtils.businessResult("0000","增加成功！");
        }else {
            return ReturnMapUtils.businessResult("9999","服务器错误，增加失败！");
        }
    }
    @RequestMapping(value = "/fundManageCon/ajax/getItemList",method = RequestMethod.POST)
    @ResponseBody
    public Map getItemList(HttpServletRequest request){
        IMap params = new IMap(request);
        Page page = PageView.startPageForTable(params, false);
        List<IMap> itemList = fundService.getItemList(params);
        Map<String, Object> result = PageView.getResultForTable(page, itemList);
        return result;
    }
}
